package com.java.service.impl;

import com.java.entity.Collec;
import com.java.entity.Malfunctions;
import com.java.entity.Orders;
import com.java.entity.User;
import com.java.mapper.UserMapper;
import com.java.service.UserService;
import com.java.util.PageUtil;
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User login(String userName, String userPassword) {
        return userMapper.selectByNameAndPwd(userName,userPassword);
    }

    @Override
    public Boolean register(User user) {
        Boolean flag=userMapper.registerUser(user);
        return flag;
    }

    @Override
    public User registerPre(String userIdcard) {

         return userMapper.registerPre(userIdcard);

    }

    @Override
    public User registerPree(String userName) {
        return userMapper.regiesterPree(userName);
    }

    @Override
    public Boolean forgetPwd(String userName, String userIdcard,String userPassword) {
        Boolean flag = userMapper.forgetPwd(userName, userIdcard,userPassword);
        return flag;
    }

    @Override
    public PageUtil<User> selectAll(Integer currentPage,Integer pageSize,String username) {
        int record = userMapper.record(username);
        PageUtil<User> pageUtil=new PageUtil<>(currentPage,pageSize,record);
        List<User> users = userMapper.selectAll(pageUtil.getStartIndex()-1, pageUtil.getPageSize(),username);
        pageUtil.setData(users);
        return pageUtil;
    }

    @Override
    public void updatePermission(String userId, Boolean permission) {
        userMapper.updatePermission(userId, permission);
    }

    @Override
    public User selectById(String userId) {
        return userMapper.selectById(userId);
    }

    @Override
    public Boolean CallForRepairs(Malfunctions malfunctions) {

        return userMapper.CallForRepairs(malfunctions);
    }

    @Override
    public List<Collec> FindAllCollecsById(int userId) {
        return userMapper.SelectAllCollecsById(userId);
    }

    @Override
    public Boolean DeleteCollecById(int userId, int houseId) {
        return userMapper.DeleteCollecById(userId,houseId);
    }

    @Override
    public List<User> FindUserByName(User user) {
        return userMapper.SelectUserByName(user);
    }

    @Override
    public Boolean UpdateUserById(User user) {
        return userMapper.UpdateUser(user);
    }

    @Override
    public List<Orders> findOrdersById(String userId) {
        return userMapper.selectOrdersById(userId);
    }

    @Override
    public void updateUsertoAdmin(User user) {
        userMapper.updateUsertoAdmin(user);
    }


}
